# coding:utf8

from appserver import db_store
from datetime import datetime
from models.entity.model_base import ModelBase


"""
巡检项管理
"""
# recorder 巡检记录员

class PatrolRecoder(ModelBase):
    __tablename__ = "patrol_recoder"
    __bind_key__ = "main"

    id = db_store.Column(db_store.Integer, primary_key=True, comment=u'主键')
    device_id = db_store.Column(db_store.Integer, db_store.ForeignKey('devices.id'), comment=u'设备')
    patrol_manage_id = db_store.Column(db_store.Integer, db_store.ForeignKey('patrol_manage.id'), comment=u'说明巡检的内容')
    patrol_content= db_store.Column(db_store.String(64),comment=u'巡检内容')
    patrol_user_id = db_store.Column(db_store.Integer, nullable=False, comment=u'巡检人员')
    patrol_time= db_store.Column(db_store.Date, comment=u'巡检时间',default=datetime.now())
    result = db_store.Column(db_store.Integer, nullable=False, comment=u'巡检结果') # 0正常 1异常
    remark = db_store.Column(db_store.String(64),comment=u'备注')
    
    def __repr__(self):
        return "<PatrolRecoder %d+%s>" % (self.id,self.patrol_time)

    @staticmethod
    def get_patrol_recoder_by_id(id_num):
        return PatrolRecoder.query.filter_by(id=id_num).first()

    @staticmethod
    def get_patrol_recoder_by_user_id(patrol_user):
        return PatrolRecoder.query.filter_by(patrol_user=patrol_user).all()

    @staticmethod
    def get_patrol_recoders_by_device_id(device_id):
        return PatrolRecoder.query.filter_by(device_id=device_id).all()
